package com.s.core.root.data;

import com.c1.client.pan.PanConf;
import com.s.core.root.D;
import com.s.core.root.strategy.base.FeatureContainer;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;

public abstract class _BasePoint extends FeatureContainer {
    public _BasePoint(_BasePic pic, D d, int total, int recentIndex) {
        this.pic = pic;
        this.d = d;
        this.total = total;
        this.recentIndex = recentIndex;
    }

    public _BasePic pic;
    public D d;
    public int total;
    public int recentIndex;

    protected abstract int posValue();

    protected abstract BigDecimal volValue();

    protected abstract InfoAndStyle yInfoValue();

    protected abstract InfoAndStyle xInfoValue();

    protected abstract PanConf.PosStyle posStyleValue();

    protected abstract PanConf.CjlStyle cjlStyleValue();

    protected void checkTp() {
        if (d.isTp()) {
            throw new RuntimeException();
        }
    }


    public int pos() {
        checkTp();
        return posValue();
    }

    public PanConf.PosStyle posStyle() {
        checkTp();
        return posStyleValue();
    }

    public PanConf.CjlStyle cjlStyle() {
        checkTp();
        return cjlStyleValue();
    }

    public BigDecimal vol() {
        checkTp();
        return volValue();
    }

    public boolean isTp() {
        return d.isTp() || posValue() == 0;
    }

    public String date() {
        return d.date;
    }

    public InfoAndStyle yInfo() {
        checkTp();
        return yInfoValue();
    }

    public InfoAndStyle xInfo() {
        checkTp();
        return xInfoValue();
    }

    public double rate() {
        BigDecimal posAvgRate = BigDecimal.valueOf(pos()).divide(BigDecimal.valueOf(total), 4, RoundingMode.HALF_UP);
        return posAvgRate.doubleValue();
    }


    @Data
    @AllArgsConstructor
    public static class InfoAndStyle {
        public String info;
        public PanConf.InfoStyle infoStyle;
    }

}
